<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>插件配置</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
<script type="text/javascript" src="/PHPUnion/Home/Lib/Pintuer/jquery-1.11.0.js"></script>
<link rel="stylesheet" type="text/css" href="/PHPUnion/Home/Lib/Pintuer/pintuer.css" />
<script type="text/javascript" src="/PHPUnion/Home/Lib/Pintuer/pintuer.js"></script>
<script type="text/javascript" src="/PHPUnion/Home/Lib/Pintuer/respond.js"></script>
</head>
<body>
    <div class="container-layout">
        <!-- 导航位置 -->
        <div class="text-small text-gray height-big">
            <div class="float-left height">
                <span class="icon-home"></span>
                当前位置： 首页 -> 扩展管理 -> 插件配置设置
            </div>
            <div class="float-right">
                <div class="radius-rounded height">
                    <button type="button" onClick="location.href='<?php echo U('index');?>'" class="button radius-none bg-sub">
                        <i class="icon-th-list"></i>
                        插件列表
                    </button>
                    <button type="button" onClick="location.href='<?php echo U('create');?>'" class="button radius-none">
                        <i class="icon-edit"></i>
                        创建插件
                    </button>
                </div>
            </div>
            <div class="clearfix"></div>
        </div>
        <hr />
        <!-- 导航位置 End -->
        <form action="<?php echo U('saveConfig');?>" method="post">
        <?php if(empty($custom_config)): if(is_array($data['config'])): foreach($data['config'] as $o_key=>$form): ?><div class="line">
                    <div class="x3 text-right padding-right">
                        <label>
                            <?php echo ((isset($form["title"]) && ($form["title"] !== ""))?($form["title"]):''); ?>
                            <?php if(isset($form["tip"])): ?><span class="check-tips">{$form.tip}</span><?php endif; ?>
                        </label>
                    </div>
                    <div class="x9">
                        <?php switch($form["type"]): case "text": ?><div>
                                <input type="text" name="config[<?php echo ($o_key); ?>]" value="<?php echo ($form["value"]); ?>">
                            </div><?php break;?>
                            <?php case "password": ?><div class="controls">
                                <input type="password" name="config[<?php echo ($o_key); ?>]" value="<?php echo ($form["value"]); ?>">
                            </div><?php break;?>
                            <?php case "hidden": ?><input type="hidden" name="config[{$o_key}]" value="{$form.value}"><?php break;?>
                            <?php case "radio": ?><div class="controls">
                                <?php if(is_array($form["options"])): foreach($form["options"] as $opt_k=>$opt): ?><label class="radio">
                                        <input type="radio" name="config[<?php echo ($o_key); ?>]" value="<?php echo ($opt_k); ?>" <?php if(($form["value"]) == $opt_k): ?>checked<?php endif; ?>><?php echo ($opt); ?>
                                    </label><?php endforeach; endif; ?>
                            </div><?php break;?>
                            <?php case "checkbox": ?><div class="controls">
                                <?php if(is_array($form["options"])): foreach($form["options"] as $opt_k=>$opt): ?><label class="checkbox">
                                        <?php is_null($form["value"]) && $form["value"] = array(); ?>
                                        <input type="checkbox" name="config[{$o_key}][]" value="{$opt_k}" <?php if(in_array(($opt_k), is_array($form["value"])?$form["value"]:explode(',',$form["value"]))): ?>checked<?php endif; ?>>{$opt}
                                    </label><?php endforeach; endif; ?>
                            </div><?php break;?>
                            <?php case "select": ?><div class="controls">
                                <select name="config[{$o_key}]">
                                    <?php if(is_array($form["options"])): foreach($form["options"] as $opt_k=>$opt): ?><option value="{$opt_k}" <?php if(($form["value"]) == $opt_k): ?>selected<?php endif; ?>>{$opt}</option><?php endforeach; endif; ?>
                                </select>
                            </div><?php break;?>
                            <?php case "textarea": ?><div class="controls">
                                <label class="textarea input-large">
                                    <textarea name="config[{$o_key}]">{$form.value}</textarea>
                                </label>
                            </div><?php break;?>
                            <?php case "picture_union": ?><div class="controls">
                                <input type="file" id="upload_picture_{$o_key}">
                                <input type="hidden" name="config[{$o_key}]" id="cover_id_{$o_key}" value="{$form.value}"/>
                                <div class="upload-img-box">
                                    <?php if(!empty($form['value'])): $mulimages = explode(",", $form["value"]); ?>
                                    <?php if(is_array($mulimages)): foreach($mulimages as $key=>$one): ?><div class="upload-pre-item" val="{$one}">
                                            <img src="{$one|get_cover='path'}"  ondblclick="removePicture{$o_key}(this)"/>
                                        </div><?php endforeach; endif; endif; ?>
                                </div>
                                </div>
                                <script type="text/javascript">
                                    //上传图片
                                    /* 初始化上传插件 */
                                    $("#upload_picture_{$o_key}").uploadify({
                                        "height"          : 30,
                                        "swf"             : "__STATIC__/uploadify/uploadify.swf",
                                        "fileObjName"     : "download",
                                        "buttonText"      : "上传图片",
                                        "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                                        "width"           : 120,
                                        'removeTimeout'   : 1,
                                        'fileTypeExts'    : '*.jpg; *.png; *.gif;',
                                        "onUploadSuccess" : uploadPicture{$o_key},
                                        'onFallback' : function() {
                                            alert('未检测到兼容版本的Flash.');
                                        }
                                    });

                                    function uploadPicture{$o_key}(file, data){
                                        var data = $.parseJSON(data);
                                        var src = '';
                                        if(data.status){
                                            src = data.url || '/PHPUnion' + data.path
                                            $("#cover_id_{$o_key}").parent().find('.upload-img-box').append(
                                                '<div class="upload-pre-item" val="' + data.id + '"><img src="/PHPUnion' + src + '" ondblclick="removePicture{$o_key}(this)"/></div>'
                                            );
                                            setPictureIds{$o_key}();
                                        } else {
                                            updateAlert(data.info);
                                            setTimeout(function(){
                                                $('#top-alert').find('button').click();
                                                $(that).removeClass('disabled').prop('disabled',false);
                                            },1500);
                                        }
                                    }
                                    function removePicture{$o_key}(o){
                                        var p = $(o).parent().parent();
                                        $(o).parent().remove();
                                        setPictureIds{$o_key}();
                                    }
                                    function setPictureIds{$o_key}(){
                                        var ids = [];
                                        $("#cover_id_{$o_key}").parent().find('.upload-img-box').find('.upload-pre-item').each(function(){
                                            ids.push($(this).attr('val'));
                                        });
                                        if(ids.length > 0)
                                            $("#cover_id_{$o_key}").val(ids.join(','));
                                        else
                                            $("#cover_id_{$o_key}").val('');
                                    }
                                </script><?php break;?>
                            <?php case "group": ?><ul class="tab-nav nav">
                                    <?php if(is_array($form["options"])): $i = 0; $__LIST__ = $form["options"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$li): $mod = ($i % 2 );++$i;?><li data-tab="tab{$i}" <?php if(($i) == "1"): ?>class="current"<?php endif; ?>><a href="javascript:void(0);">{$li.title}</a></li><?php endforeach; endif; else: echo "" ;endif; ?>
                                </ul>
                                <div class="tab-content">
                                <?php if(is_array($form["options"])): $i = 0; $__LIST__ = $form["options"];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$tab): $mod = ($i % 2 );++$i;?><div id="tab{$i}" class="tab-pane <?php if(($i) == "1"): ?>in<?php endif; ?> tab{$i}">
                                        <?php if(is_array($tab['options'])): foreach($tab['options'] as $o_tab_key=>$tab_form): ?><label class="item-label">
                                            {$tab_form.title|default=''}
                                            <?php if(isset($tab_form["tip"])): ?><span class="check-tips">{$tab_form.tip}</span><?php endif; ?>
                                        </label>
                                        <div class="controls">
                                            <?php switch($tab_form["type"]): case "text": ?><input type="text" name="config[{$o_tab_key}]" class="text input-large" value="{$tab_form.value}"><?php break;?>
                                                <?php case "password": ?><input type="password" name="config[{$o_tab_key}]" class="text input-large" value="{$tab_form.value}"><?php break;?>
                                                <?php case "hidden": ?><input type="hidden" name="config[{$o_tab_key}]" value="{$tab_form.value}"><?php break;?>
                                                <?php case "radio": if(is_array($tab_form["options"])): foreach($tab_form["options"] as $opt_k=>$opt): ?><label class="radio">
                                                            <input type="radio" name="config[{$o_tab_key}]" value="{$opt_k}" <?php if(($tab_form["value"]) == $opt_k): ?>checked<?php endif; ?>>{$opt}
                                                        </label><?php endforeach; endif; break;?>
                                                <?php case "checkbox": if(is_array($tab_form["options"])): foreach($tab_form["options"] as $opt_k=>$opt): ?><label class="checkbox">
                                                            <?php is_null($tab_form["value"]) && $tab_form["value"] = array(); ?>
                                                            <input type="checkbox" name="config[{$o_tab_key}][]" value="{$opt_k}" <?php if(in_array(($opt_k), is_array($tab_form["value"])?$tab_form["value"]:explode(',',$tab_form["value"]))): ?>checked<?php endif; ?>>{$opt}
                                                        </label><?php endforeach; endif; break;?>
                                                <?php case "select": ?><select name="config[{$o_tab_key}]">
                                                        <?php if(is_array($tab_form["options"])): foreach($tab_form["options"] as $opt_k=>$opt): ?><option value="{$opt_k}" <?php if(($tab_form["value"]) == $opt_k): ?>selected<?php endif; ?>>{$opt}</option><?php endforeach; endif; ?>
                                                    </select><?php break;?>
                                                <?php case "textarea": ?><label class="textarea input-large">
                                                        <textarea name="config[{$o_tab_key}]">{$tab_form.value}</textarea>
                                                    </label><?php break;?>
                                                <?php case "picture_union": ?><div class="controls">
                                                    <input type="file" id="upload_picture_{$o_tab_key}">
                                                    <input type="hidden" name="config[{$o_tab_key}]" id="cover_id_{$o_tab_key}" value="{$tab_form.value}"/>
                                                    <div class="upload-img-box">
                                                        <?php if(!empty($tab_form['value'])): $mulimages = explode(",", $tab_form["value"]); ?>
                                                        <?php if(is_array($mulimages)): foreach($mulimages as $key=>$one): ?><div class="upload-pre-item" val="{$one}">
                                                                <img src="{$one|get_cover='path'}"  ondblclick="removePicture{$o_tab_key}(this)"/>
                                                            </div><?php endforeach; endif; endif; ?>
                                                    </div>
                                                    </div>
                                                    <script type="text/javascript">
                                                        //上传图片
                                                        /* 初始化上传插件 */
                                                        $("#upload_picture_{$o_tab_key}").uploadify({
                                                            "height"          : 30,
                                                            "swf"             : "__STATIC__/uploadify/uploadify.swf",
                                                            "fileObjName"     : "download",
                                                            "buttonText"      : "上传图片",
                                                            "uploader"        : "{:U('File/uploadPicture',array('session_id'=>session_id()))}",
                                                            "width"           : 120,
                                                            'removeTimeout'   : 1,
                                                            'fileTypeExts'    : '*.jpg; *.png; *.gif;',
                                                            "onUploadSuccess" : uploadPicture{$o_tab_key},
                                                            'onFallback' : function() {
                                                                alert('未检测到兼容版本的Flash.');
                                                            }
                                                        });

                                                        function uploadPicture{$o_tab_key}(file, data){
                                                            var data = $.parseJSON(data);
                                                            var src = '';
                                                            if(data.status){
                                                                src = data.url || '/PHPUnion' + data.path
                                                                $("#cover_id_{$o_tab_key}").parent().find('.upload-img-box').append(
                                                                    '<div class="upload-pre-item" val="' + data.id + '"><img src="/PHPUnion' + src + '" ondblclick="removePicture{$o_tab_key}(this)"/></div>'
                                                                );
                                                                setPictureIds{$o_tab_key}();
                                                            } else {
                                                                updateAlert(data.info);
                                                                setTimeout(function(){
                                                                    $('#top-alert').find('button').click();
                                                                    $(that).removeClass('disabled').prop('disabled',false);
                                                                },1500);
                                                            }
                                                        }
                                                        function removePicture{$o_tab_key}(o){
                                                            var p = $(o).parent().parent();
                                                            $(o).parent().remove();
                                                            setPictureIds{$o_tab_key}();
                                                        }
                                                        function setPictureIds{$o_tab_key}(){
                                                            var ids = [];
                                                            $("#cover_id_{$o_tab_key}").parent().find('.upload-img-box').find('.upload-pre-item').each(function(){
                                                                ids.push($(this).attr('val'));
                                                            });
                                                            if(ids.length > 0)
                                                                $("#cover_id_{$o_tab_key}").val(ids.join(','));
                                                            else
                                                                $("#cover_id_{$o_tab_key}").val('');
                                                        }
                                                    </script><?php break; endswitch;?>
                                            </div><?php endforeach; endif; ?>
                                    </div><?php endforeach; endif; else: echo "" ;endif; ?>
                                </div><?php break; endswitch;?>
                    </div>
                </div><?php endforeach; endif; ?>
        <?php else: ?>
            <?php if(isset($custom_config)): ?>{$custom_config}<?php endif; endif; ?>
        <input type="hidden" name="id" value="<?php echo I('id');?>" readonly>
        <button type="submit" class="button bg-sub radius-none">
            <i class="icon-check-square-o"></i>
            确 定
        </button>
        <button type="button" class="button radius-none" onclick="javascript:history.back(-1);return false;">
            <i class="icon-edit"></i>
            返 回
        </button>
    </form>
</div>
</body>
</html>